package com.example.springbootfuture.async;

import com.example.springbootfuture.factory.MyThreadFactory;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * @author: wukangrong
 * @date: 2020/8/28 14:51
 * @description: 将后续函数封装进线程run方法内，进而实现类似于回调函数功能
 */
@Slf4j
public class TestCallBa {

    static ExecutorService executor = Executors.newFixedThreadPool(2);

    static ThreadPoolExecutor executor2 = new ThreadPoolExecutor(1, 5,
            5L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(15), new MyThreadFactory());


    public static void main(String[] args) {

        executor2.allowCoreThreadTimeOut(true);
        dos(System.out::println);
        System.out.println("0k");
    }

    public static void dos(CallBack callBack) {

        executor2.submit(() -> {
            try {
                Thread.sleep(2000);
                log.info("23");
                callBack.doIt("21");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

    }
}
